package net.shopxx.service.impl;

import net.shopxx.service.PayService;
import net.shopxx.util.SystemConfigUtil;

import org.springframework.stereotype.Service;

/**
 * Service实现类 - 管理员
 * 
 * chinapay.PrivateKey key=new chinapay.PrivateKey(); chinapay.SecureLink t;
 * boolean flag; String MerId, OrdId, TransAmt, CuryId, TransDate,
 * TransType,ChkValue; String plainData, ChkValue2 ;
 * 
 * flag=key.buildKey(MerId,0,"app/usr/chinapay/keys/MerPrk.key"); if
 * (flag==false) { System.out.println("build key error!"); return; } t=new
 * chinapay.SecureLink (key); // 对订单的签名 ChkValue= t.signOrder(MerId, OrdId,
 * TransAmt, CuryId, TransDate, TransType) ; // 对一段字符串的签名 plainData = "test sign
 * data "; ChkValue2 = t.sign(plainData) ;
 * 
 * 
 * chinapay.PrivateKey key=new chinapay.PrivateKey(); chinapay.SecureLink t;
 * boolean flag; boolean flag1; String MerId, OrdId, TransAmt, CuryId,
 * TransDate, TransType,ChkValue; String plainData, ChkValue2
 * flag=key.buildKey("999999999999999",0,"c:\\winnt\\PgPubk.key"); if
 * (flag==false) { msg="build key error!"; return; } t=new chinapay.SecureLink
 * (key); flag1=t.verifyTransResponse(MerId,OrdId, TransAmt, CuryId, TransDate,
 * TransType, OrderStatus, ChkValue); // ChkValue为ChinaPay应答传回的域段 if(flag1!=0) {
 * //签名验证错误处理 }
 *  // 对一段字符串的签名验证 plainData = "test sign data "; flag1 = t. verifyAuthToken
 * (plainData, ChkValue2) ; // ChkValue2为ChinaPay应答传回的域段 if(flag1) { //签名验证错误处理 }
 * 
 */

@Service
public class UnionPayServiceImpl implements PayService {

	@Override
	public String getMerId() {
		return null;
	}

	@Override
	public String getMerPrk() {
		return null;
	}

	@Override
	public String getPgPubk() {
		return null;
	}

	@Override
	public String sign(String signMsg) throws Throwable {
//		PrivateKey key=new PrivateKey(); 
//		SecureLink t; 
		boolean flag = false; 
		String MerId, OrdId, TransAmt,CuryId, TransDate, TransType,ChkValue = null;
		String plainData, ChkValue2 ;
//		flag= key.buildKey(getMerId(),0,getMerPrk()); 
		if (flag==false) 
		{ 
			throw new Exception("签名错误");
		} 
//		t=new SecureLink (key); 
		// 对订单的签名
//		ChkValue= t.signOrder(MerId, OrdId, TransAmt, CuryId, TransDate, TransType) ; 
		// 对一段字符串的签名
//		plainData = "test sign data ";
//		ChkValue2 = t.sign(plainData) ;
		return ChkValue;
	}

	@Override
	public String signOrder() {
		return null;
	}

	@Override
	public boolean verifyAuthToken(String PlainData, String CheckValue) {
		return false;
	}

	@Override
	public boolean verifyTransResponse(String checkValue, String painText) {
//		PrivateKey key=new PrivateKey(); 
//		SecureLink t; 
		boolean flag; 
		String MerId, OrdId, TransAmt, CuryId, TransDate, TransType,ChkValue;
		String plainData, ChkValue2;
//		flag=key.buildKey(getMerId(),0,getPgPubk()); 
//		if (flag==false) 
//		{ 
//		} 
//		t=new SecureLink(key); 
//		flag=t.verifyTransResponse(MerId,OrdId, TransAmt, CuryId, TransDate, TransType, OrderStatus, ChkValue);  // ChkValue为ChinaPay应答传回的域段
//		if(flag) {
//			//签名验证错误处理
//		}

		return false;
	}

	@Override
	public String getPayUrl() {
		return null;
	}

	@Override
	public String getRefundUrl() {
		return null;
	}

	@Override
	public String getBgRetUrl() {
		return SystemConfigUtil.getSystemConfig().getShopUrl()
				+ "pay/pay!upBgRet.action";
	}

	@Override
	public String getRefundRetUrl() {
		return SystemConfigUtil.getSystemConfig().getShopUrl()
				+ "pay/pay!upRefundRet.action";
	}

	@Override
	public String getRetUrl() {
		return SystemConfigUtil.getSystemConfig().getShopUrl()
				+ "pay/pay!upRet.action";
	}

}